<?php
$dt = new DataTable(constant('DB_TABLE_PRODUCT'));
$GLOBALS['PAGE_ROW_DATA'] = $dt->get(intval($_REQUEST['id']));
$GLOBALS['send_success'] = FALSE;
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if($act == 'send')
{
	$name =  $GLOBALS['PAGE_ROW_DATA']['name'].' 金額：'.$GLOBALS['PAGE_ROW_DATA']['price'].'元';
	$uname = $_REQUEST['name'];
	$phone = $_REQUEST['phone'];
	$description = $_REQUEST['note'];
	send_out_order_email($name,$uname,$phone,$description);
	$GLOBALS['send_success'] = TRUE;
}
else{
if ( SessionUtil::getVar(constant('SESSION_KEY_MEM_HAS_LOGIN'))) {
	$dt = new DataTable(constant('DB_TABLE_MEMBER'));
	$member_data = $dt->get(SessionUtil::getVar(constant('SESSION_KEY_MEM_USER_ID')));
	$GLOBALS['PAGE_MEM_NAME'] = $member_data['display_name'];
	$GLOBALS['PAGE_MEM_PHONE'] = $member_data['phone'];
}else{
	$GLOBALS['PAGE_MEM_NAME'] = '';
	$GLOBALS['PAGE_MEM_PHONE'] = '';
}
}

function send_out_order_email($name,$uname,$phone,$description)
{
	$body = file_get_contents(constant ( 'APP_DIR' ) . '/config/order_email_template.html');
	$body = preg_replace('/\[\[\$NAME\]\]/',$name,$body);
	$body = preg_replace('/\[\[\$UNAME\]\]/',$uname,$body);
	$body = preg_replace('/\[\[\$PHONE\]\]/',$phone,$body);
	$body = preg_replace('/\[\[\$DESCRIPTION\]\]/',$description,$body);

	$email = constant('SITE_ADMIN_EMAIL');
	$GLOBALS['APP_INSTANCE']->send_out_email($email,'班尼頓寫真.縣上預約',$body);


}
?>